import Nav from '../../src/components/common/nav/nav.vue'
import {ApiUrl,Islogined,returnId,show,hide} from './ApiUrl.js'
import loading from '../../src/components/common/loading/loading.vue'
import fangerror from '../../src/components/common/fangerror/fangerror.vue'
import {timerScale} from '../plugins/scale/self_adaption_scale'
import Vue from 'vue'
import VueScroller from 'vue-scroller'
Vue.use(VueScroller)
require("./lib/select2/js/select2.min");
export default {
  components: {
    meun:Nav,loading,fangerror,
  },
  data(){
    return {
      FangLoading:false,//Loading控制，true显示，false不显示
      fangerroring:false,//提示文本弹窗，true显示，false不显示
      fangerrorText:'',//提示文本弹窗内容
      headerTitle:'我的主材',
      isRed: false,
      tableData:[],  //接收数据数组
      noData:'',
      page:1,
    }
  },
  created: function() {

  },
  mounted(){
    timerScale();
    $('.select2-dropdown').remove();
    $('select').select2({
      language: "zh-CN",
    });

    let windowH = $(window).height();
    let meunBoxH = $('.meunBox').outerHeight(true);
    let megessBoxH = $('.megessBox').outerHeight(true);
    $('.contentLeft,.contentRight').height( windowH - meunBoxH - megessBoxH );
    $('.tab_box').height(windowH - meunBoxH);

    this.getTableData();
  },
  methods:{
    setTimeoutError:function () {
      setTimeout(() => {
        $('.Fang_errorBox').hide()
        this.fangerroring = false
      }, 2000)
    },
    getTableData:function (fn) {
      let _This = this;
      let params = {
        page:1,
        pageSize:8
      };
      _This.dataAjax(params,function(data){
        _This.tableData = data;
      })
    },
    backDetail:function () {
      this.isRed = true;  //返回按钮变红色
      this.$router.push({path: 'detail'});
    },
    delData:function (id) {
      let _This = this;
      _This.FangLoading = true;
      let params ={
        id:id
      };
      _This.FnAxiosAjax('post','/api/indexattrsubscription/deletebyids',params,function () {
        mui.confirm('确定要删除我吗？','提示',['确定','删除'],function (e) {   //提示弹窗
          if(e.index == 0){  //按钮下标
            _This.tableData.splice(index,1);   //删除
          }else {
            return
          }
        })
      })
    },
    toDetailFeature:function (id) {   //查看详情
      this.$router.push({path: 'detaiFeaturel?id='+id});  //传id
    },
    //表格上拉加载更多
    infinite(done) {
      let _This = this;
      // if(this.noData) {
      //   setTimeout(() => {
      //     _This.$refs.indexsublist.finishInfinite(2);
      //   });
      //   return;
      // }
      _This.page =  _This.page + 1;
      setTimeout(() => {
        _This.$nextTick(()=>{
          if(_This.tableData.length >= 10){
            let params = {
              id:_This.mainMatId,
              page:_This.page,
              pageSize:10
            };
            _This.dataAjax(params,function (data) {   //上拉时发送请求
              if(data=='' || data == null){
                done(true);//没有更多数据
              }else {
                done();
              }
              if(_This.tableData == ''){
                _This.tableData = data;
              }else {
                for(let key in data){
                  _This.tableData.push(data[key]);
                }
              }
            });
          }
        })
      }, 500)
      //回调选中数据 specialtyCode,indexType,parent,page,pageSize,fn
    },
    dataAjax:function (params,fn) {
      let _This = this;
      _This.FnAxiosAjax('post','/api/matfeatures',params,function (data) {
        !! fn && fn(data.results);
      })
    }

  }
}
